package com.sdcx.agrobank.ui.my_activity;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.sdcx.agrobank.R;
import com.sdcx.agrobank.bean.JiLuBean;
import com.sdcx.agrobank.bean.MingXIBean;
import com.sdcx.agrobank.event.myEvent;
import com.sdcx.agrobank.event.tjEvent;
import com.sdcx.agrobank.ui.activity.MingxiActivity;
import com.sdcx.agrobank.util.ACache;
import com.sdcx.agrobank.util.ListDataSave;
import com.sdcx.agrobank.util.date.DialogChooseDate;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

public class jiluActivity extends AppCompatActivity {

    private ImageView back;
    private TextView zhichu, tianjia;
    private TextView shouru;
    private ImageView canyin1;
    private ImageView chuxing1;
    private ImageView hongbao1;
    private ImageView fangzu1;
    private ImageView xiuxian1;
    private ImageView yiliao1;
    private ImageView chongzhi1;
    private ImageView gouwu1;
    private ImageView gengduo1;
    private ImageView wenti1;
    private ImageView xinchou1;
    private ImageView hongbao0;
    private ImageView baoxiao1;
    private ImageView touzi1;
    private ImageView shebao1;
    private ImageView jiekuan1;
    private ImageView tuikuan1;
    private ImageView xianjin1;
    private ImageView taren1;
    private ImageView gengduo2;
    private String type="餐饮";
    private int ZS=1;
    private EditText jine;
    private EditText beizhu;
    private TextView timeSelect;
    private String dates = "2020-11-14";
    private ArrayList<JiLuBean> list;
    private ACache cache;
    private ListDataSave dataSave;

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onmyEvent(tjEvent myEvent) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jilu);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }

        back = findViewById(R.id.back);
        zhichu = findViewById(R.id.zhichu);
        shouru = findViewById(R.id.shouru);
        tianjia = findViewById(R.id.tianjia);
        jine = findViewById(R.id.jine);
        beizhu = findViewById(R.id.beizhu);
        timeSelect = findViewById(R.id.timeselect);
        LinearLayout top1 = findViewById(R.id.top1);
        LinearLayout bottom1 = findViewById(R.id.bottom1);

        LinearLayout top2 = findViewById(R.id.top2);
        LinearLayout bottom2 = findViewById(R.id.bottom2);
        canyin1 = findViewById(R.id.canyin1);
        chuxing1 = findViewById(R.id.chuxing1);
        hongbao1 = findViewById(R.id.hongbao1);
        fangzu1 = findViewById(R.id.fangzu1);
        xiuxian1 = findViewById(R.id.xiuxian1);
        yiliao1 = findViewById(R.id.yiliao1);
        chongzhi1 = findViewById(R.id.chongzhi1);
        gouwu1 = findViewById(R.id.gouwu1);
        gengduo1 = findViewById(R.id.gengduo1);
        wenti1 = findViewById(R.id.wenti1);

        /*下*/
        xinchou1 = findViewById(R.id.xinchou1);
        hongbao0 = findViewById(R.id.hongbao0);
        baoxiao1 = findViewById(R.id.baoxiao1);
        touzi1 = findViewById(R.id.touzi1);
        shebao1 = findViewById(R.id.shebao1);
        jiekuan1 = findViewById(R.id.jiekuan1);
        tuikuan1 = findViewById(R.id.tuikuan1);
        xianjin1 = findViewById(R.id.xianjin1);
        taren1 = findViewById(R.id.taren1);
        gengduo2 = findViewById(R.id.gengduo2);

        canyin1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                canyin1.setImageResource(R.mipmap.canyin1);
                chuxing1.setImageResource(R.mipmap.chuxing2);
                hongbao1.setImageResource(R.mipmap.hongbao2);
                fangzu1.setImageResource(R.mipmap.fangzu2);
                xiuxian1.setImageResource(R.mipmap.xiuxian2);
                yiliao1.setImageResource(R.mipmap.yiliao2);
                chongzhi1.setImageResource(R.mipmap.chongzhi2);
                gouwu1.setImageResource(R.mipmap.gouwu2);
                wenti1.setImageResource(R.mipmap.wenti2);
                gengduo1.setImageResource(R.mipmap.gengduo2);
                type = "餐饮";
            }
        });
        chuxing1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                canyin1.setImageResource(R.mipmap.canyin2);
                chuxing1.setImageResource(R.mipmap.chuxing1);
                hongbao1.setImageResource(R.mipmap.hongbao2);
                fangzu1.setImageResource(R.mipmap.fangzu2);
                xiuxian1.setImageResource(R.mipmap.xiuxian2);
                yiliao1.setImageResource(R.mipmap.yiliao2);
                chongzhi1.setImageResource(R.mipmap.chongzhi2);
                gouwu1.setImageResource(R.mipmap.gouwu2);
                wenti1.setImageResource(R.mipmap.wenti2);
                gengduo1.setImageResource(R.mipmap.gengduo2);
                type = "出行";
            }
        });
        hongbao1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                canyin1.setImageResource(R.mipmap.canyin2);
                chuxing1.setImageResource(R.mipmap.chuxing2);
                hongbao1.setImageResource(R.mipmap.hongbao1);
                fangzu1.setImageResource(R.mipmap.fangzu2);
                xiuxian1.setImageResource(R.mipmap.xiuxian2);
                yiliao1.setImageResource(R.mipmap.yiliao2);
                chongzhi1.setImageResource(R.mipmap.chongzhi2);
                gouwu1.setImageResource(R.mipmap.gouwu2);
                wenti1.setImageResource(R.mipmap.wenti2);
                gengduo1.setImageResource(R.mipmap.gengduo2);
                type = "红包";
            }
        });
        fangzu1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                canyin1.setImageResource(R.mipmap.canyin2);
                chuxing1.setImageResource(R.mipmap.chuxing2);
                hongbao1.setImageResource(R.mipmap.hongbao2);
                fangzu1.setImageResource(R.mipmap.fangzu1);
                xiuxian1.setImageResource(R.mipmap.xiuxian2);
                yiliao1.setImageResource(R.mipmap.yiliao2);
                chongzhi1.setImageResource(R.mipmap.chongzhi2);
                gouwu1.setImageResource(R.mipmap.gouwu2);
                wenti1.setImageResource(R.mipmap.wenti2);
                gengduo1.setImageResource(R.mipmap.gengduo2);
                type = "房租房贷";
            }
        });
        xiuxian1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                canyin1.setImageResource(R.mipmap.canyin2);
                chuxing1.setImageResource(R.mipmap.chuxing2);
                hongbao1.setImageResource(R.mipmap.hongbao2);
                fangzu1.setImageResource(R.mipmap.fangzu2);
                xiuxian1.setImageResource(R.mipmap.xiuxian1);
                yiliao1.setImageResource(R.mipmap.yiliao2);
                chongzhi1.setImageResource(R.mipmap.chongzhi2);
                gouwu1.setImageResource(R.mipmap.gouwu2);
                wenti1.setImageResource(R.mipmap.wenti2);
                gengduo1.setImageResource(R.mipmap.gengduo2);
                type = "休闲娱乐";
            }
        });
        yiliao1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                canyin1.setImageResource(R.mipmap.canyin2);
                chuxing1.setImageResource(R.mipmap.chuxing2);
                hongbao1.setImageResource(R.mipmap.hongbao2);
                fangzu1.setImageResource(R.mipmap.fangzu2);
                xiuxian1.setImageResource(R.mipmap.xiuxian2);
                yiliao1.setImageResource(R.mipmap.yiliao1);
                chongzhi1.setImageResource(R.mipmap.chongzhi2);
                gouwu1.setImageResource(R.mipmap.gouwu2);
                wenti1.setImageResource(R.mipmap.wenti2);
                gengduo1.setImageResource(R.mipmap.gengduo2);
                type = "医疗保健";
            }
        });
        chongzhi1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                canyin1.setImageResource(R.mipmap.canyin2);
                chuxing1.setImageResource(R.mipmap.chuxing2);
                hongbao1.setImageResource(R.mipmap.hongbao2);
                fangzu1.setImageResource(R.mipmap.fangzu2);
                xiuxian1.setImageResource(R.mipmap.xiuxian2);
                yiliao1.setImageResource(R.mipmap.yiliao2);
                chongzhi1.setImageResource(R.mipmap.chongzhi1);
                gouwu1.setImageResource(R.mipmap.gouwu2);
                wenti1.setImageResource(R.mipmap.wenti2);
                gengduo1.setImageResource(R.mipmap.gengduo2);
                type = "充值缴费";
            }
        });
        gouwu1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                canyin1.setImageResource(R.mipmap.canyin2);
                chuxing1.setImageResource(R.mipmap.chuxing2);
                hongbao1.setImageResource(R.mipmap.hongbao2);
                fangzu1.setImageResource(R.mipmap.fangzu2);
                xiuxian1.setImageResource(R.mipmap.xiuxian2);
                yiliao1.setImageResource(R.mipmap.yiliao2);
                chongzhi1.setImageResource(R.mipmap.chongzhi2);
                gouwu1.setImageResource(R.mipmap.gouwu1);
                wenti1.setImageResource(R.mipmap.wenti2);
                gengduo1.setImageResource(R.mipmap.gengduo2);
                type = "购物";
            }
        });
        wenti1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                canyin1.setImageResource(R.mipmap.canyin2);
                chuxing1.setImageResource(R.mipmap.chuxing2);
                hongbao1.setImageResource(R.mipmap.hongbao2);
                fangzu1.setImageResource(R.mipmap.fangzu2);
                xiuxian1.setImageResource(R.mipmap.xiuxian2);
                yiliao1.setImageResource(R.mipmap.yiliao2);
                chongzhi1.setImageResource(R.mipmap.chongzhi2);
                gouwu1.setImageResource(R.mipmap.gouwu2);
                wenti1.setImageResource(R.mipmap.wenti1);
                gengduo1.setImageResource(R.mipmap.gengduo2);
                type = "文体教育";
            }
        });

        gengduo1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                canyin1.setImageResource(R.mipmap.canyin2);
                chuxing1.setImageResource(R.mipmap.chuxing2);
                hongbao1.setImageResource(R.mipmap.hongbao2);
                fangzu1.setImageResource(R.mipmap.fangzu2);
                xiuxian1.setImageResource(R.mipmap.xiuxian2);
                yiliao1.setImageResource(R.mipmap.yiliao2);
                chongzhi1.setImageResource(R.mipmap.chongzhi2);
                gouwu1.setImageResource(R.mipmap.gouwu2);
                wenti1.setImageResource(R.mipmap.wenti2);
                gengduo1.setImageResource(R.mipmap.gengduo1);
                type = "更多";
            }
        });
        gengduo2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xinchou1.setImageResource(R.mipmap.canyin2);
                hongbao0.setImageResource(R.mipmap.hongbao2);
                baoxiao1.setImageResource(R.mipmap.baoxiao2);
                touzi1.setImageResource(R.mipmap.touzi2);
                shebao1.setImageResource(R.mipmap.shebao2);
                jiekuan1.setImageResource(R.mipmap.jiekuan2);
                tuikuan1.setImageResource(R.mipmap.tuikuan2);
                xianjin1.setImageResource(R.mipmap.xianjin2);
                taren1.setImageResource(R.mipmap.taren2);
                gengduo2.setImageResource(R.mipmap.gengduo1);
                type = "更多";
            }
        });
        xinchou1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xinchou1.setImageResource(R.mipmap.canyin1);
                hongbao0.setImageResource(R.mipmap.hongbao2);
                baoxiao1.setImageResource(R.mipmap.baoxiao2);
                touzi1.setImageResource(R.mipmap.touzi2);
                shebao1.setImageResource(R.mipmap.shebao2);
                jiekuan1.setImageResource(R.mipmap.jiekuan2);
                tuikuan1.setImageResource(R.mipmap.tuikuan2);
                xianjin1.setImageResource(R.mipmap.xianjin2);
                taren1.setImageResource(R.mipmap.taren2);
                gengduo2.setImageResource(R.mipmap.gengduo2);
                type = "薪酬";
            }
        });
        hongbao0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xinchou1.setImageResource(R.mipmap.canyin2);
                hongbao0.setImageResource(R.mipmap.hongbao1);
                baoxiao1.setImageResource(R.mipmap.baoxiao2);
                touzi1.setImageResource(R.mipmap.touzi2);
                shebao1.setImageResource(R.mipmap.shebao2);
                jiekuan1.setImageResource(R.mipmap.jiekuan2);
                tuikuan1.setImageResource(R.mipmap.tuikuan2);
                xianjin1.setImageResource(R.mipmap.xianjin2);
                taren1.setImageResource(R.mipmap.taren2);
                gengduo2.setImageResource(R.mipmap.gengduo2);
                type = "红包";
            }
        });
        baoxiao1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xinchou1.setImageResource(R.mipmap.canyin2);
                hongbao0.setImageResource(R.mipmap.hongbao2);
                baoxiao1.setImageResource(R.mipmap.baoxiao1);
                touzi1.setImageResource(R.mipmap.touzi2);
                shebao1.setImageResource(R.mipmap.shebao2);
                jiekuan1.setImageResource(R.mipmap.jiekuan2);
                tuikuan1.setImageResource(R.mipmap.tuikuan2);
                xianjin1.setImageResource(R.mipmap.xianjin2);
                taren1.setImageResource(R.mipmap.taren2);
                gengduo2.setImageResource(R.mipmap.gengduo2);
                type = "报销";
            }
        });
        touzi1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xinchou1.setImageResource(R.mipmap.canyin2);
                hongbao0.setImageResource(R.mipmap.hongbao2);
                baoxiao1.setImageResource(R.mipmap.baoxiao2);
                touzi1.setImageResource(R.mipmap.touzi1);
                shebao1.setImageResource(R.mipmap.shebao2);
                jiekuan1.setImageResource(R.mipmap.jiekuan2);
                tuikuan1.setImageResource(R.mipmap.tuikuan2);
                xianjin1.setImageResource(R.mipmap.xianjin2);
                taren1.setImageResource(R.mipmap.taren2);
                gengduo2.setImageResource(R.mipmap.gengduo2);
                type = "投资收益";
            }
        });
        shebao1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xinchou1.setImageResource(R.mipmap.canyin2);
                hongbao0.setImageResource(R.mipmap.hongbao2);
                baoxiao1.setImageResource(R.mipmap.baoxiao2);
                touzi1.setImageResource(R.mipmap.touzi2);
                shebao1.setImageResource(R.mipmap.shebao1);
                jiekuan1.setImageResource(R.mipmap.jiekuan2);
                tuikuan1.setImageResource(R.mipmap.tuikuan2);
                xianjin1.setImageResource(R.mipmap.xianjin2);
                taren1.setImageResource(R.mipmap.taren2);
                gengduo2.setImageResource(R.mipmap.gengduo2);
                type = "社保公积金";
            }
        });
        jiekuan1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xinchou1.setImageResource(R.mipmap.canyin2);
                hongbao0.setImageResource(R.mipmap.hongbao2);
                baoxiao1.setImageResource(R.mipmap.baoxiao2);
                touzi1.setImageResource(R.mipmap.touzi2);
                shebao1.setImageResource(R.mipmap.shebao2);
                jiekuan1.setImageResource(R.mipmap.jiekuan1);
                tuikuan1.setImageResource(R.mipmap.tuikuan2);
                xianjin1.setImageResource(R.mipmap.xianjin2);
                taren1.setImageResource(R.mipmap.taren2);
                gengduo2.setImageResource(R.mipmap.gengduo2);
                type = "借款";
            }
        });
        tuikuan1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xinchou1.setImageResource(R.mipmap.canyin2);
                hongbao0.setImageResource(R.mipmap.hongbao2);
                baoxiao1.setImageResource(R.mipmap.baoxiao2);
                touzi1.setImageResource(R.mipmap.touzi2);
                shebao1.setImageResource(R.mipmap.shebao2);
                jiekuan1.setImageResource(R.mipmap.jiekuan2);
                tuikuan1.setImageResource(R.mipmap.tuikuan1);
                xianjin1.setImageResource(R.mipmap.xianjin2);
                taren1.setImageResource(R.mipmap.taren2);
                gengduo2.setImageResource(R.mipmap.gengduo2);
                type = "退款";
            }
        });
        xianjin1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xinchou1.setImageResource(R.mipmap.canyin2);
                hongbao0.setImageResource(R.mipmap.hongbao2);
                baoxiao1.setImageResource(R.mipmap.baoxiao2);
                touzi1.setImageResource(R.mipmap.touzi2);
                shebao1.setImageResource(R.mipmap.shebao2);
                jiekuan1.setImageResource(R.mipmap.jiekuan2);
                tuikuan1.setImageResource(R.mipmap.tuikuan2);
                xianjin1.setImageResource(R.mipmap.xianjin1);
                taren1.setImageResource(R.mipmap.taren2);
                gengduo2.setImageResource(R.mipmap.gengduo2);
                type = "现金";
            }
        });
        taren1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xinchou1.setImageResource(R.mipmap.canyin2);
                hongbao0.setImageResource(R.mipmap.hongbao2);
                baoxiao1.setImageResource(R.mipmap.baoxiao2);
                touzi1.setImageResource(R.mipmap.touzi2);
                shebao1.setImageResource(R.mipmap.shebao2);
                jiekuan1.setImageResource(R.mipmap.jiekuan2);
                tuikuan1.setImageResource(R.mipmap.tuikuan2);
                xianjin1.setImageResource(R.mipmap.xianjin2);
                taren1.setImageResource(R.mipmap.taren1);
                gengduo2.setImageResource(R.mipmap.gengduo2);
                type = "他人转入";
            }
        });


        zhichu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                zhichu.setBackgroundResource(R.drawable.tv_yellor);
                shouru.setBackgroundResource(0);
                zhichu.setTextColor(Color.argb(255, 249, 116, 35));
                shouru.setTextColor(Color.argb(255, 64, 64, 64));
                ZS = 1;
                top1.setVisibility(View.VISIBLE);
                bottom1.setVisibility(View.VISIBLE);
                top2.setVisibility(View.GONE);
                bottom2.setVisibility(View.GONE);
            }
        });
        shouru.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shouru.setBackgroundResource(R.drawable.tv_yellor);
                zhichu.setBackgroundResource(0);
                shouru.setTextColor(Color.argb(255, 249, 116, 35));
                zhichu.setTextColor(Color.argb(255, 64, 64, 64));
                ZS = 2;
                top2.setVisibility(View.VISIBLE);
                bottom2.setVisibility(View.VISIBLE);
                top1.setVisibility(View.GONE);
                bottom1.setVisibility(View.GONE);
            }
        });
        timeSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new DialogChooseDate(jiluActivity.this, 1, new DialogChooseDate.Dialogcallback() {
                    @Override
                    public void pickWeightResult(String sex) {
                        timeSelect.setText(sex);
                        dates = sex;
                    }
                }).show();

            }
        });
        list = new ArrayList<>();
        cache = ACache.get(this);
        ArrayList<MingXIBean> list1 = new ArrayList<>();
        tianjia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String jin = jine.getText().toString();
                // String zs = ZS;
                //    String ty = jiluActivity.this.type;
                String bz = beizhu.getText().toString() != "" ? beizhu.getText().toString() : "";
                MingxiActivity.list.add(new MingXIBean(type, dates, jin, bz, ZS));
            //    cache.put("data",list);
                dataSave = new ListDataSave(jiluActivity.this, "list");
                dataSave.setDataList("datas", MingxiActivity.list);
                EventBus.getDefault().post(new tjEvent());
                finish();
                //  list.add(new JiLuBean(jin, zs, ty, bz, dates));
            }
        });
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}